<?php

namespace common\models;


use Yii;

/**
 * This is the model class for table "d_try.order_goods".
 *
 * @property integer $order_goods_id
 * @property integer $order_info_id
 * @property integer $goods_id
 * @property integer $product_id
 * @property integer $bestry_uid
 * @property integer $buy_number
 * @property double $buy_price
 * @property string $create_time
 * @property integer $free_gift
 * @property integer $commented
 * @property integer $activity_type_id
 * @property integer $activity_id
 * @property integer $price_type
 * @property integer $try_coin
 *
 * @property OrderInfo $orderInfo
 */
class OrderGoodsHistory extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'd_order_history.order_goods';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['order_info_id', 'goods_id', 'product_id', 'bestry_uid', 'buy_number', 'free_gift', 'commented', 'activity_type_id', 'activity_id', 'price_type', 'try_coin'], 'integer'],
            [['buy_price'], 'number'],
            [['create_time'], 'safe'],
            [['order_info_id'], 'exist', 'skipOnError' => true, 'targetClass' => OrderInfo::className(), 'targetAttribute' => ['order_info_id' => 'order_info_id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'order_goods_id' => 'Order Goods ID',
            'order_info_id' => '订单id',
            'goods_id' => '商品id',
            'product_id' => '货品id',
            'bestry_uid' => '会员id',
            'buy_number' => '购买数量',
            'buy_price' => '实际购买的价格',
            'create_time' => '添加时间',
            'free_gift' => '是否有赠品 0 无 1有',
            'commented' => '是否有评论 0无， 1 有',
            'activity_type_id' => '活动类型',
            'activity_id' => '如果是买赠，加价购活动，则保存活动ID',
            'price_type' => '价格类型',
            'try_coin' => '试豆数量',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getOrderInfo()
    {
        return $this->hasOne(OrderInfo::className(), ['order_info_id' => 'order_info_id']);
    }

    /**
     * @inheritdoc
     * @return \services\models\OrderGoodsQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new \services\models\OrderGoodsQuery(get_called_class());
    }

}
